// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sys

import (
	"context"
	"hotgo/api/admin/distribution"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
)

var (
	Distribution = cDistribution{}
)

type cDistribution struct{}

// List 查看分销记录列表
func (c *cDistribution) List(ctx context.Context, req *distribution.ListReq) (res *distribution.ListRes, err error) {
	list, totalCount, err := service.SysDistribution().List(ctx, &req.DistributionListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.DistributionListModel{}
	}

	res = new(distribution.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出分销记录列表
func (c *cDistribution) Export(ctx context.Context, req *distribution.ExportReq) (res *distribution.ExportRes, err error) {
	err = service.SysDistribution().Export(ctx, &req.DistributionListInp)
	return
}

// Edit 更新分销记录
func (c *cDistribution) Edit(ctx context.Context, req *distribution.EditReq) (res *distribution.EditRes, err error) {
	err = service.SysDistribution().Edit(ctx, &req.DistributionEditInp)
	return
}

// View 获取指定分销记录信息
func (c *cDistribution) View(ctx context.Context, req *distribution.ViewReq) (res *distribution.ViewRes, err error) {
	data, err := service.SysDistribution().View(ctx, &req.DistributionViewInp)
	if err != nil {
		return
	}

	res = new(distribution.ViewRes)
	res.DistributionViewModel = data
	return
}

// Delete 删除分销记录
func (c *cDistribution) Delete(ctx context.Context, req *distribution.DeleteReq) (res *distribution.DeleteRes, err error) {
	err = service.SysDistribution().Delete(ctx, &req.DistributionDeleteInp)
	return
}

// Status 更新分销记录状态
func (c *cDistribution) Status(ctx context.Context, req *distribution.StatusReq) (res *distribution.StatusRes, err error) {
	err = service.SysDistribution().Status(ctx, &req.DistributionStatusInp)
	return
}